package com.sc.pattern.guardedsuspension;

import java.util.Random;

/**
 * Created  on 2018/1/7.
 *
 * @author sc
 */
public class ClientThread extends Thread{
    final RequestQueue queue;
    private final Random random;
    private final String url;
    public ClientThread(RequestQueue queue,String url){
        this.queue = queue;
        this.url =url;
        random = new Random(System.currentTimeMillis());
    }

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println("Client->request"+url);
            queue.putRequest(new Request(url));
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
